package tp01;

import java.io.IOException;
import javax.comm.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TCPConnectionController extends ConnectionController {
    
    //Bajar active port
    static CommPortIdentifier portId1;
    static SerialPort serialPort1;
    static Thread readThread;
    private static Socket socket;
    private int numeroPuerto; 
    
    public TCPConnectionController(int numeroPuerto){
        this.numeroPuerto = numeroPuerto;
    }

    @Override
    public void conectar() {
        try {
            
            socket = new Socket("localhost", numeroPuerto);
            ConnectionController.inputStream = socket.getInputStream();
            ConnectionController.outputStream = socket.getOutputStream();
            System.out.println("\u00a1\u00a1Conecci\u00f3n exitosa!!");
            
        } catch (IOException ex) {
            Logger.getLogger(ConnectionController.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }

    @Override
    public void desconectar() {
        try {
            ConnectionController.inputStream.close();
            ConnectionController.outputStream.close();
            serialPort1.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            Logger.getLogger(ConnectionController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
